﻿using Scala.Compiler.Binding;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Scala.Compiler.Types
{
    public class InternalTypes
    {
        public static bool GetType(string typename, ScalaScope scope, out Type type)
        {
            switch (typename)
            {
                case "Int": type = typeof(int);
                    return true;
                case "Boolean": type = typeof(bool);
                    return true;
                case "Unit": type = typeof(void);
                    return true;
                case "String": type = typeof(string);
                    return true;
                default: break;
            }
            ScalaType t;
            for (var sc = scope; sc != null; sc = sc.ParentScope)
            {
                if (sc.Types.TryGetValue(typename, out t))
                {
                    type = t.TypeBuilder.AsType();
                    return true;
                }
            }
            type = null;
            return false;
        }
    }
}
